import { RootState, RootThunkAction } from "@/types/store"
import { useEffect } from "react"
import { useDispatch, useSelector } from "react-redux"

// 封装自定义函数
export const useInitState = (fn: () => RootThunkAction) => {
    const dispatch = useDispatch()
    useEffect(() => {
        dispatch(fn())
    }, [dispatch, fn])
    const state = useSelector<RootState, RootState>((state) => state)
    return state
}